package edu.ccut.saturn.manager.bundles.core;

import java.util.ArrayList;
import java.util.List;

import edu.ccut.saturn.component.ComponentManager;
import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IComponentInfo;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.IParameterInfo;
import edu.ccut.saturn.component.IValidateInfo;
import edu.ccut.saturn.component.IValidateUseInfo;
import edu.ccut.saturn.component.impl.SaturnLogicComponentInfo;

public class GetParamValidateInfoAction extends DefaultComponent {
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {

		String fullKey = (String) parameterContext.getParameterValue(0);
		String nodeId = (String) parameterContext.getParameterValue(1);
		String paramId = (String) parameterContext.getParameterValue(2);
	
		IComponentInfo componentInfo = ComponentManager.getInstance()
				.getComponentInfo(fullKey);
		List<IParameterInfo> paramInfos = ((SaturnLogicComponentInfo) componentInfo)
				.getNodeInfo(nodeId).getParameterInfos();
		IParameterInfo paramInfo = paramInfos
				.get(Integer.parseInt(paramId) - 1);
		IValidateUseInfo validateUse = paramInfo.getValidateUses();
		
		List<IValidateInfo> validateList = new ArrayList<IValidateInfo>();		
		
		if(validateUse != null){			
			validateList = validateUse.getValidateInfos();
		}
		parameterContext.setParameter(3, validateList);
	}
}